#ifndef __PROTOCOLDEF__
#define __PROTOCOLDEF__
//////////////////////////////////////////////////////////////////////////////
// Protocol used

#define PMHC_BYTE				0xC1 // The client sends 1 byte protocol
#define PMHC_WORD				0xC2 // The client sends 2 byte protocol
#define PMHCE_BYTE				0xC3 // The client sends 1 byte protocol
#define PMHCE_WORD				0xC4 // The client sends 2 byte protocol

#define SET_NUMBERH(x) ( (BYTE)((DWORD)(x)>>(DWORD)8) )
#define SET_NUMBERL(x) ( (BYTE)((DWORD)(x) & 0xFF) )

typedef struct
{
	void set(LPBYTE lpBuf, BYTE head, BYTE size)
	{
		lpBuf[0] = PMHC_BYTE;
		lpBuf[1] = size;
		lpBuf[2] = head;
	};
	
	void setE(LPBYTE lpBuf, BYTE head, BYTE size)
	{
		lpBuf[0] = PMHCE_BYTE;
		lpBuf[1] = size;
		lpBuf[2] = head;
	};
	
	BYTE c;			// Protocol code
	BYTE size;		// Protocol size (including header size)
	BYTE headcode;	// Protocol type
} PBMSG_HEAD, *LPPBMSG_HEAD;

typedef struct
{
	void set(LPBYTE lpBuf, BYTE head, int size)
	{
		lpBuf[0] = PMHC_WORD;
		lpBuf[1] = SET_NUMBERH(size);
		lpBuf[2] = SET_NUMBERL(size);
		lpBuf[3] = head;
	};
	
	void setE(LPBYTE lpBuf, BYTE head, int size)
	{
		lpBuf[0] = PMHCE_WORD;
		lpBuf[1] = SET_NUMBERH(size);
		lpBuf[2] = SET_NUMBERL(size);
		lpBuf[3] = head;
	};
	
	BYTE c;			// Protocol code
	BYTE sizeH;		// Protocol size (including header size) Top
	BYTE sizeL;
	BYTE headcode;	// Protocol type
} PWMSG_HEAD, *LPPWMSG_HEAD;

typedef struct
{
	void set(LPBYTE lpBuf, BYTE head, BYTE sub, BYTE size)
	{
		lpBuf[0] = PMHC_BYTE;
		lpBuf[1] = size;
		lpBuf[2] = head;
		lpBuf[3] = sub;
	};
	
	BYTE c;			// Protocol code
	BYTE size;		// Protocol size (including header size)
	BYTE headcode;	// Protocol type
	BYTE subcode;	// Sub-protocol types
} PBMSG_HEAD2, * LPPBMSG_HEAD2;

typedef struct
{
	void set(LPBYTE lpBuf, BYTE head, BYTE sub, int size)
	{
		lpBuf[0] = PMHC_WORD;
		lpBuf[1] = SET_NUMBERH(size);
		lpBuf[2] = SET_NUMBERL(size);
		lpBuf[3] = head;
		lpBuf[4] = sub;
	}
	
	BYTE c;			// Protocol code
	BYTE sizeH;		// Protocol, the high byte size
	BYTE sizeL;		// Magnitude lower byte protocol
	BYTE headcode;	// Protocol type
	BYTE subcode;	// Sub-protocol types
} PWMSG_HEAD2, * LPPWMSG_HEAD2;

//----------------------------------------------------------------------------
// Counter
//----------------------------------------------------------------------------
typedef struct
{
	PBMSG_HEAD	h;
	BYTE		count;
} PBMSG_COUNT, * LPPBMSG_COUNT;

//----------------------------------------------------------------------------
// Counter
//----------------------------------------------------------------------------
typedef struct
{
	PWMSG_HEAD	h;
	BYTE		count;
} PWMSG_COUNT, * LPPWMSG_COUNT;

//----------------------------------------------------------------------------
// SUBCODE a counter
//----------------------------------------------------------------------------
typedef struct
{
	PBMSG_HEAD	h;
	BYTE		subcode;
	BYTE		count;
} PBMSGS_COUNT, * LPPBMSGS_COUNT;

#endif
